package com.example.gridviewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.GridView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private GridView gridView;
    private ArrayList<Fruit> fruits = new ArrayList<>();

    private String[] data = {"Apple","Banana", "Orange", "Watermelon", "Pear", "Grape",
            "Pineapple","Strawberry", "Cherry", "Mango","Peach" ,"Shaddock" };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initData();


        gridView = findViewById(R.id.grid_view);
        FruitAdapter fruitAdapter = new FruitAdapter(this, R.layout.fruit_item,  fruits);
        gridView.setAdapter(fruitAdapter);
    }

    private void initData() {
        for (int i = 0; i < 1; i++) {
            Fruit apple = new Fruit(data[0], R.drawable.apple_pic);
            fruits.add(apple);
            Fruit banana = new Fruit(data[1], R.drawable.banana_pic);
            fruits.add(banana);
            Fruit orange = new Fruit(data[2], R.drawable.orange_pic);
            fruits.add(orange);
            Fruit watermelon = new Fruit(data[3], R.drawable.watermelon_pic);
            fruits.add(watermelon);
            Fruit pear = new Fruit(data[4], R.drawable.pear_pic);
            fruits.add(pear);

//
//            Fruit grape = new Fruit(data[5], R.drawable.grape_pic);
//            fruits.add(grape);
//            Fruit pineapple = new Fruit(data[6], R.drawable.pineapple_pic);
//            fruits.add(pineapple);
//            Fruit strawberry = new Fruit(data[7], R.drawable.strawberry_pic);
//            fruits.add(strawberry);
//            Fruit cherry = new Fruit(data[8], R.drawable.cherry_pic);
//            fruits.add(cherry);
//            Fruit mango = new Fruit(data[9], R.drawable.mango_pic);
//            fruits.add(mango);
//            Fruit peach = new Fruit(data[10], R.drawable.peach_pic);
//            fruits.add(peach);
//            Fruit shaddock = new Fruit(data[11], R.drawable.shaddock_pic );
//            fruits.add(shaddock);
        }
    }

}
